package com.ruoyi.whzj.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.whzj.domain.WhActivityUser;
import com.ruoyi.whzj.service.IWhActivityUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动参与人员Controller
 * 
 * @author ruoyi
 * @date 2020-10-22
 */
@Controller
@RequestMapping("/whzj/activityuser")
public class WhActivityUserController extends BaseController
{
    private String prefix = "whzj/activityuser";

    @Autowired
    private IWhActivityUserService whActivityUserService;

    @RequiresPermissions("whzj:activityuser:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/activityuser";
    }

    /**
     * 查询活动参与人员列表
     */
    @RequiresPermissions("whzj:activityuser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WhActivityUser whActivityUser)
    {
        startPage();
        List<WhActivityUser> list = whActivityUserService.selectWhActivityUserList(whActivityUser);
        return getDataTable(list);
    }

    /**
     * 查询活动参与人员列表
     */
    @RequiresPermissions("whzj:activityuser:list")
    @PostMapping("/listByActivity")
    @ResponseBody
    public TableDataInfo listByActivity(String id)
    {
        startPage();
        WhActivityUser whActivityUser = new WhActivityUser();
        whActivityUser.setActivityId(id);
        List<WhActivityUser> list = whActivityUserService.selectWhActivityUserList(whActivityUser);
        return getDataTable(list);
    }

    /**
     * 导出活动参与人员列表
     */
    @RequiresPermissions("whzj:activityuser:export")
    @Log(title = "活动参与人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WhActivityUser whActivityUser)
    {
        List<WhActivityUser> list = whActivityUserService.selectWhActivityUserList(whActivityUser);
        ExcelUtil<WhActivityUser> util = new ExcelUtil<WhActivityUser>(WhActivityUser.class);
        return util.exportExcel(list, "user");
    }

    /**
     * 新增活动参与人员
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存活动参与人员
     */
    @RequiresPermissions("whzj:activityuser:add")
    @Log(title = "活动参与人员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WhActivityUser whActivityUser)
    {
        return toAjax(whActivityUserService.insertWhActivityUser(whActivityUser));
    }

    /**
     * 修改活动参与人员
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        WhActivityUser whActivityUser = whActivityUserService.selectWhActivityUserById(id);
        mmap.put("whActivityUser", whActivityUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存活动参与人员
     */
    @RequiresPermissions("whzj:activityuser:edit")
    @Log(title = "活动参与人员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WhActivityUser whActivityUser)
    {
        return toAjax(whActivityUserService.updateWhActivityUser(whActivityUser));
    }

    /**
     * 删除活动参与人员
     */
    @RequiresPermissions("whzj:activityuser:remove")
    @Log(title = "活动参与人员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(whActivityUserService.deleteWhActivityUserByIds(ids));
    }
}
